/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.hymnal.church;

/**
 *
 * @author Vsevolod Kazakov
 */
public class refactoring {
    
    static final int MAX_HYMNS_COUNT = 551;
    
    static final String pathCommonArg = new String("-pathCommon");
    static final String pathTableFileArg = new String("-tableFile");
    static final String pathToMelodyArg = new String("-pathMelody");    
    
    static String pathToHymns;
    static String tableFile;
    static String pathToMelody;
    
    static HymnsReader hymnsReader = null;  
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        //Open common hymns.
        try {
            loadArgs(args);
        } catch (IllegalArgumentException argEx) {
            System.out.println("Argmnets exception, check args:" + argEx.getMessage());
            return;
        }
        hymnsReader = new HymnsReader(pathToHymns);    
        
        hymnsReader.readHymns();
        TableManager.printSystemOutAllTable();
        
        HymnsNetReader.saveAllMidiFiles(pathToMelody);
        TableManager.saveTableFile(tableFile);
        
    }
    
    private static void loadArgs(String[] args) throws IllegalArgumentException{
        if(args.length == 0) {
            System.out.println("No arguments.");
        }
        if(pathCommonArg.equals(args[0])) {
            pathToHymns = args[1];
            System.out.println("Path to hymns:" + pathToHymns);
        } else {
            System.out.println("Error -path to common hymns incorrect.");
        }        
        
        if(pathTableFileArg.equals(args[2])) {
            tableFile = args[3];
            System.out.println("Table file:" + tableFile);
        } else {
            System.out.println("Error -table file incorrect.");
        }        
        if(pathToMelodyArg.equals(args[4])) {
            pathToMelody = args[5];
            System.out.println("Path to melody:" + pathToMelody);
        } else {
            System.out.println("Error -table file");
        }        
        if((pathToHymns == null) || (tableFile==null) || (pathToMelody ==null)) {
            throw new IllegalArgumentException("Check " + pathCommonArg + "," + pathTableFileArg + "," + pathToMelodyArg);
        }            
    }    
}
